package lk.icta.core.entity;

import lk.icta.common.entity.BaseEntity;
import lk.icta.common.entity.DSDivision;
import lk.icta.common.entity.Document;
import lk.icta.common.entity.GNDivision;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @author Kusal Samarakoon
 */
@Entity
@Table(schema = "ELAND_RAIL")
@NamedQueries({
        @NamedQuery(name = "getAllKachcheryByState", query = "SELECT s FROM Kachchery s WHERE s.status =:status"),
        @NamedQuery(name = "getKachcheryById", query = "SELECT s FROM Kachchery s WHERE s.id = :id"),
        @NamedQuery(
                name = "getAllKachcheryByDSDivisionAndState",
                query = "SELECT s FROM Kachchery s WHERE " +
                        " (1 = :ignoreDS AND s.status =:status) OR " +
                        "(0 = :ignoreDS AND s.status =:status AND s.dsDivision IN (:DSList))"

        )
})
public class Kachchery  extends BaseEntity {

    public enum Status {
        INACTIVE, /**
         * 0 - Inactive record
         */
        ACTIVE, /**
         * 1 -  Active record--Approved by PLC
         */
        PENDING,      /** 2 - Pending record */
        APPROVE_ORDS,      /** 3 - Approved by ORDS */
        REJECT_ORDS,      /** 4 - Rejected by ORDS */
        REJECT_PLC,      /** 5 - Rejected by PLC */
        ATTACH_DOC_LO      /** 6 - Attach by LO */
    }

    /**
     * status - The record is active or inactive or pending
     */
    @Column(nullable = false)
    private Status status;

    /**
     * Kachchery date of the Schedule
     */
    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date kachcheryDate;


    @Column(nullable = true)
    private String name;

    @Column(nullable = true)
    private String description;

    @ManyToOne
    @JoinColumn(nullable = false)
    private DSDivision dsDivision;

    /**
     * The LandAssociation List
     */

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(schema = "ELAND_RAIL")
    private Set<LandAssociation> landAssociationList;

    @Column(nullable = true, columnDefinition = "text")
    private String comment;

    @Transient
    private List<Document> documentList;

    @Embedded
    private LifeCycleInfo lifeCycleInfo = new LifeCycleInfo();

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Date getKachcheryDate() {
        return kachcheryDate;
    }

    public void setKachcheryDate(Date kachcheryDate) {
        this.kachcheryDate = kachcheryDate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public DSDivision getDsDivision() {
        return dsDivision;
    }

    public void setDsDivision(DSDivision dsDivision) {
        this.dsDivision = dsDivision;
    }


    public Set<LandAssociation> getLandAssociationList() {
        return landAssociationList;
    }

    public void setLandAssociationList(Set<LandAssociation> landAssociationList) {
        this.landAssociationList = landAssociationList;
    }

    public LifeCycleInfo getLifeCycleInfo() {
        return lifeCycleInfo;
    }

    public void setLifeCycleInfo(LifeCycleInfo lifeCycleInfo) {
        this.lifeCycleInfo = lifeCycleInfo;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public List<Document> getDocumentList() {
        return documentList;
    }

    public void setDocumentList(List<Document> documentList) {
        this.documentList = documentList;
    }


}
